package com.fyh.mapper;

import com.fyh.entity.user.JobFavorite;
import com.fyh.entity.user.Vitae;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface CandidateMapper {

    /**
     * 添加用户简历
     */
    @Insert("insert into vitae (user_id, update_time, create_time) values (#{userId}, #{updateTime}, #{createTime})")
    void insertVitae(Vitae vitae);

    /**
     * 修改用户简历
     */
    void updateVitae(Vitae vitae);

    /**
     * 删除用户技能标签
     */
    @Delete("delete from user_skill where user_id = #{userId}")
    void deleteTagByUserId(Long userId);

    /**
     * 添加用户技能标签
     */
    @Insert("insert into user_skill (user_id, tag_name) values (#{userId}, #{tagName})")
    void insertTag(@Param("userId") Long userId, @Param("tagName") String tagName);

    /**
     * 获取用户简历
     */
    @Select("select * from vitae where user_id = #{userId}")
    Vitae getUserVitae(Long userId);

    /**
     * 获取用户技能标签
     */
    @Select("select tag_name from user_skill where user_id = #{userId}")
    List<String> getTagNameListByUserId(Long userId);

    /**
     * 收藏职位
     */
    @Insert("insert into job_favorite (position_id, user_id, create_time) values (#{positionId}, #{userId}, #{createTime})")
    void collectJob(@Param("positionId") Long positionId, @Param("userId") Long userId, @Param("createTime") LocalDateTime createTime);

    /**
     * 取消收藏职位
     */
    @Insert("delete from job_favorite where position_id = #{positionId} and user_id = #{userId}")
    void cancelCollectJob(@Param("positionId") Long positionId, @Param("userId") Long userId);

    /**
     * 获取收藏职位状态
     */
    @Select("select exists(select 1 from job_favorite where position_id = #{positionId} and user_id = #{userId})")
    Boolean getCollectExist(@Param("positionId") Long positionId, @Param("userId") Long userId);

    /**
     * 获取收藏职位列表
     */
    @Select("select * from job_favorite where user_id = #{userId} order by create_time DESC")
    List<JobFavorite> getJobFavoriteList(Long userId);
}
